package com.freewater.springboot.demo.dataaccess.jdbc.customtraslator;

import org.jetbrains.annotations.NotNull;
import org.springframework.dao.DataAccessException;
import org.springframework.dao.PessimisticLockingFailureException;
import org.springframework.jdbc.support.SQLExceptionTranslator;

import java.sql.SQLException;

public class CustomSQLErrorCodesTranslator implements SQLExceptionTranslator {

    @Override
    public DataAccessException translate(@NotNull String task, String sql, SQLException ex) {
        if (ex.getErrorCode() == -12345) {
            return new PessimisticLockingFailureException(task, ex);
        }
        return null;
    }
}